package com.tj.ocr.util;

import java.awt.image.BufferedImage;

import com.tj.ocr.img.BlankWhiteUtil;
import com.tj.ocr.img.LinePop;
import com.tj.ocr.img.MyImage;
import com.tj.ocr.img.TextPop;
import com.tj.ocr.similar.TextSearcher;

public class OcrUtil {

	public static TextSearcher tsMySelf;
	public static TextSearcher tsFriends;
	
	public static void init(String modelPath, int startPos){
		tsMySelf = TextSearcher.load(modelPath+"\\outtsv1_m.bin");
		tsFriends = TextSearcher.load(modelPath + "\\outtsv1_f.bin");
		
		//init start pos
		TextPop.start_pos = startPos;
	}
	
	public static String ocrMySelf(BufferedImage bi){
		String ret  = "";
		MyImage mi = BlankWhiteUtil.procEx(bi, 160);

		LinePop lpop = new LinePop(mi);
		while ((mi = lpop.pop()) != null) {
			ret += (tsMySelf.doTextSearch(mi));
		}
		
		return ret;
	}
	
	public static String ocrFriends(BufferedImage bi){
		String ret  = "";
		MyImage mi = BlankWhiteUtil.procEx(bi, 160);

		LinePop lpop = new LinePop(mi);
		while ((mi = lpop.pop()) != null) {
			ret += (tsFriends.doTextSearch(mi));
		}
		
		return ret;
	}
}
